import os
import matplotlib.image as mpimg  # mpimg 用于读取图片
from PIL import Image

# 平衡样本数
def dealImageTo100():
    path = 'CharSample_Gen/'
    label_path = os.listdir(path)

    for label_name in label_path:
        image_name_list = os.listdir(path + str(label_name))
        i = 0
        isExists = os.path.exists('CharSample_Gen_Deal/' + str(label_name))
        if not isExists:
            os.makedirs('CharSample_Gen_Deal/' + str(label_name))
        else:
            pass
        while i < 100:
            img = Image.open(path + str(label_name) + '/' + image_name_list[i])
            img.save('CharSample_Gen_Deal/' + str(label_name) + '/' + str(i) + '.jpg')
            i += 1
# 混合数据集
def mixDataSet():
    path = 'CharSample_Gen_Deal/'
    imagesAutoaugment = 'imagesAutoaugment/'
    imagesAutoaugmentPath_path = os.listdir(imagesAutoaugment)

    for label_name in imagesAutoaugmentPath_path:
        pre_data_name = os.listdir(path + label_name + '/')
        pre_data_name = pre_data_name[:50]
        for i in range(len(pre_data_name)):
            img = Image.open(path + label_name + '/' + pre_data_name[i])
            img.save(imagesAutoaugment + label_name + '/' + str(i + 100) + '.jpg')


if __name__ == '__main__':
    # 平衡类别为100
    # print([str(i) for i in range(200)])
    mixDataSet()
